{php}
    $this->assign('tracks', array_splice($this->_tpl_vars['form']['elements'], 4)); 
    $this->assign('upload_file', array_splice($this->_tpl_vars['form']['elements'], 0, 1)); 
    //$this->assign('settings', array_splice($this->_tpl_vars['form']['elements'], 0, 2)); 
{/php}

{title}Generate cue sheet{/title}

{include file="_form/header.tpl" action=$BASE_PATH enctype="multipart/form-data"}
<div id="intro">
    You can fill in Tracklist <span class="emphasis">manually</span> or upload a text file with Tracklist to parse <span class="emphasis">automatically</span>.
</div>

<div id="upload_tracklist">
    
    {if isset($form.errors.tracklist)}
    <div class="upload_tracklist_error">
        {if $form.errors.tracklist}
            {$form.errors.tracklist}
        {else}
            {"FILE_WAS_NOT_CHOSEN"|translate}
        {/if}
    </div>
    {/if}

    {assign var="element" value=$upload_file.tracklist}
    {include file="component/form/"|cat:$element.template|cat:".tpl" name="tracklist"}
    {include file="_form/footer.tpl" submit="Upload Tracklist"}
    <div class="notice">Allowed file mime-type is <span class="emphasis">plain text</span></div>
</div>

<hr id="form_separator" />

{*<div id="settings_link">Settings</div>
<div id="settings" class="no-display">
    {foreach from=$settings item="element" key="name"}
        <div class="element">
            <label for="{$name|id}">{$element.caption|translate}</label> 
            <span class="note" id="what_is_{$name|id}">?</span><br />
            {include file="component/form/"|cat:$element.template|cat:".tpl"}
            <div id="explanation_{$name|id}" class="explanation no-display">{$element.notice}</div>
        </div>
    {/foreach}
</div>
<div class="clear"></div>*}

{assign var="columns" value=6}
{include file="_form/header.tpl" enctype="application/x-www-form-urlencoded"}

<table id="common_info">
    {foreach from=$form.elements item="element" key="name"}
        <tr>
            <td class="caption{if isset($form.errors[$name])} error_color{/if}">
                {$element.caption|translate}
                {if isset($form.errors[$name])}
                    <div class="common_error">Specify {$element.caption|translate}</div>
                {/if}
            </td>
            <td class="element">
                {include file="component/form/"|cat:$element.template|cat:".tpl"}
            </td>
        </tr>
    {/foreach}
</table>

{if array_key_exists('perfomer[1]', $form.errors) or 
    array_key_exists('title[1]', $form.errors) or 
    array_key_exists('perfomer[2]', $form.errors) or 
    array_key_exists('title[2]', $form.errors)} 
    
    <div class="tracklist_error">Specify mimimum first 2 fileds</div>
{/if}
<table id="tracklist">
    <thead>
        <tr>
            <th class="number">#</th>
            <th class="perfomer">Perfomer</th>
            <th class="title">Title</th>
            <th class="time">hr:mn:sc.fr</th>
            <th class="edit"><span class="add_row" title="Add row below">+</span></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            
            <td class="number{if array_key_exists('perfomer[1]', $form.errors) or array_key_exists('title[1]', $form.errors)} error_color{/if}">1</td>
        {foreach from=$tracks key="name" item="element" name="tracks"}
            {assign var="iteration" value=$smarty.foreach.tracks.iteration}
            
            {if 0 == ($iteration - 1) % $columns}<td class="perfomer">{/if}
            {if 0 == ($iteration - 2) % $columns}<td class="title">{/if}
            {if 0 == ($iteration - 3) % $columns}<td class="time">{/if}
                
                {include file="component/form/"|cat:$element.template|cat:".tpl"}
            
            {if 
            0 == ($iteration - 1) % $columns or 
            0 == ($iteration - 2) % $columns or 
            0 == ($iteration - 6) % $columns
            }</td>{/if}
            
            
            
            {if 0 == $iteration % $columns and $iteration < $tracks|@count}
                <td class="edit"><span class="delete_row" title="Delete current row">-</span> <span class="add_row" title="Add row below">+</span></td></tr>
                <tr><td class="number{if 2 == $iteration/$columns+1}{if array_key_exists('perfomer[2]', $form.errors) or array_key_exists('title[2]', $form.errors)} error_color{/if}{/if}">{$iteration/$columns+1}</td>
            {/if}
            
        {/foreach}
            <td class="edit"><span class="delete_row" title="Delete current row">-</span> <span class="add_row" title="Add row below">+</span></td>
        </tr>
    </tbody>
</table>

{include file="_form/footer.tpl" submit="Confirm Tracklist"}